'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ManageLendidCtrl
 * @description
 * # ManageLendidCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('ManageLendidCtrl', function ($scope, openApi, Util, $location, $routeParams, FormSubmit) {
        var id = $scope.process_id = $routeParams.id
        $scope.choosePeople = function () {
            var relModuleObj = {
                name: "ManageLendidCtrl",
                selectTab: "bid_apply",
                selectTabContent: "投标申请单"
            };
            Util.savaParamForReview($scope.param, id);
            Util.savaDataforsearch(relModuleObj);

            $location.path("finance/choosepeople")
        };
        //获取证件信息列表
        $scope.getChoosecertId = function () {
            Util.saveSelectLists($scope.param.certificates);
            Util.savaParamForReview($scope.param, id);
            $location.path("manage/chooseinfo/jzj");
        };
        // 删除证件信息列表
        $scope.deletedItem = function (index) {
            $scope.param.certificates.splice(index, 1);
            $scope.index = -1;
            Util.saveSelectLists($scope.param.certificates);
        };
        var getAllcerIds = function () {
            var cerIds = [],
                cerIdsStr;
            $scope.param.certificates.forEach(function (item, index) {
                cerIds.push(item.cerId);
            });
            cerIdsStr = cerIds.join(",");
            return cerIdsStr;
        }
        $scope.submit = function (operationId) {

            $scope.param.cerIds = getAllcerIds();
            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.certificateApply;
            options.param = angular.copy($scope.param, {});
            delete options.param.certificates
            delete options.param.formBidApply
            FormSubmit.submit(options,$scope);
        };
        $scope.swipe=function(index){
            $scope.index=index;
        }
        $scope.resetlist=function(index){
            $scope.index=-1;
        }
        $scope.validate = function () {
            if (!$scope.param.returnDate) {
                Util.Toast("请选择预计归还日期");
                return;
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }
        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData(id, function (data) {
                $scope.param = data;
                if($scope.param.formBidApply){
                    $scope.param["formBidApply.formId"]=$scope.param.formBidApply.formId
                }
                // 获取选择页面返回的数据并且合并到参数中
                var selectLists = Util.getSelectLists();
                // 获取选择页面返回的数据并且合并到参数中
                $scope.param.certificates = selectLists || $scope.param.certificates || [];

            });
        };
        // 初始化
        init();
    });